import $http from "@/utils/apiHelper";
import Oidc from 'oidc-client'

const state = {
  system: [],
  userManager: undefined,
};

const mutations = {
  setConfig(state, val) {
    if (val) {
      state.system = val;
    }
  },

  setUserManager(state, manager) {
    state.userManager = manager;
  },
};

const actions = {
  async loadSystemConfig({ commit }) {
    let result = await $http
      .get("/EQDictionary/GetSystemConfig")
      .catch((error) => console.error("get baseConfig error..." + error));
    if (result && result.Data) {
      commit("setConfig", result.Data);
      let settings = result.Data.find((x) => x.ConfigName == "Oid").Config;
      if (settings) {

        console.log("@@@settingsconfig",JSON.parse(settings))
        let manager = new Oidc.UserManager(JSON.parse(settings));
        commit("setUserManager", manager);
      }
    }
  },
};

export default {
  state,
  mutations,
  actions,
};
